<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


//登录成功 ---index.php

//登录不成功---提示出错

header('Content-Type:text/html;charset=utf-8');

$error=array();
if (empty($_POST)==false)
{
    //用户填写登录信息，点击提交
    $username=isset($_REQUEST['username'])?trim($_REQUEST['username']):'';
    $password=isset($_REQUEST['password'])?trim($_REQUEST['password']):'';
    require 'dbcon.php';
    $sql="select * from tb_user where username='{$username}'";
    $result=$db->query($sql);
    $sum=$result->num_rows;            
    if ($sum>0)
    {        
        $row=$result->fetch_array();
        if ($row['password']==$password)
        {
            //登录成功,产生登录成功的标记



            session_start();

            $_SESSION['userinfo']=array('uid'=>$row['uid'],'username'=>$row['username']);
            header('location:index.php');
            die;
        }
        else 
        {
            $error[]="密码错误！";
        }
    }
   else {
       $error[]="用户名不存在！"; 
    }
    
    
}
require 'login_html.php';